/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.CalendarResourceBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Provisioning.SetPasswordResult;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.message.SetPasswordRequest;
/*     */ import com.zimbra.soap.admin.message.SetPasswordResponse;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class SetPassword
/*     */   extends AdminDocumentHandler
/*     */ {
/*  48 */   private static final String[] TARGET_ACCOUNT_PATH = { "id" };
/*     */   
/*  50 */   protected String[] getProxiedAccountPath() { return TARGET_ACCOUNT_PATH; }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  57 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean defendsAgainstDelegateAdminAccountHarvesting()
/*     */   {
/*  65 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  70 */     SetPasswordResponse resp = null;
/*  71 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  72 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  74 */     SetPasswordRequest req = (SetPasswordRequest)JaxbUtil.elementToJaxb(request);
/*  75 */     String id = req.getId();
/*  76 */     String newPassword = req.getNewPassword();
/*     */     
/*  78 */     Account account = prov.get(Key.AccountBy.id, id, zsc.getAuthToken());
/*  79 */     if (account == null) {
/*     */       try {
/*  81 */         defendAgainstAccountOrCalendarResourceHarvestingWhenAbsent(Key.AccountBy.id, id, zsc, Rights.Admin.R_setAccountPassword, Rights.Admin.R_setCalendarResourcePassword);
/*     */       }
/*     */       catch (ServiceException se1) {
/*  84 */         defendAgainstAccountOrCalendarResourceHarvestingWhenAbsent(Key.AccountBy.id, id, zsc, Rights.Admin.R_changeAccountPassword, Rights.Admin.R_changeCalendarResourcePassword);
/*     */       }
/*     */     }
/*     */     else {
/*     */       try {
/*  89 */         defendAgainstAccountOrCalendarResourceHarvesting(account, Key.AccountBy.id, id, zsc, Rights.Admin.R_setAccountPassword, Rights.Admin.R_setCalendarResourcePassword);
/*     */       }
/*     */       catch (ServiceException se1) {
/*  92 */         defendAgainstAccountOrCalendarResourceHarvesting(account, Key.AccountBy.id, id, zsc, Rights.Admin.R_changeAccountPassword, Rights.Admin.R_changeCalendarResourcePassword);
/*     */       }
/*     */       boolean enforcePasswordPolicy;
/*     */       boolean enforcePasswordPolicy;
/*  96 */       if (account.isCalendarResource()) {
/*  97 */         CalendarResource resource = prov.get(Key.CalendarResourceBy.id, id);
/*  98 */         enforcePasswordPolicy = checkCalendarResourceRights(zsc, resource);
/*     */       } else {
/* 100 */         enforcePasswordPolicy = checkAccountRights(zsc, account);
/*     */       }
/*     */       
/* 103 */       Provisioning.SetPasswordResult result = prov.setPassword(account, newPassword, enforcePasswordPolicy);
/*     */       
/* 105 */       ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "SetPassword", "name", account.getName() }));
/*     */       
/*     */ 
/*     */ 
/* 109 */       if (result.hasMessage()) {
/* 110 */         ZimbraLog.security.info(result.getMessage());
/* 111 */         resp = new SetPasswordResponse(result.getMessage());
/*     */       } else {
/* 113 */         resp = new SetPasswordResponse((String)null);
/*     */       }
/*     */     }
/*     */     
/* 117 */     return zsc.jaxbToElement(resp);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private boolean checkAccountRights(ZimbraSoapContext zsc, Account acct)
/*     */     throws ServiceException
/*     */   {
/*     */     try
/*     */     {
/* 131 */       checkAccountRight(zsc, acct, Rights.Admin.R_setAccountPassword);
/* 132 */       return false;
/*     */     } catch (ServiceException e) {
/* 134 */       if ("service.PERM_DENIED".equals(e.getCode())) {
/* 135 */         checkAccountRight(zsc, acct, Rights.Admin.R_changeAccountPassword);
/* 136 */         return true;
/*     */       }
/* 138 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private boolean checkCalendarResourceRights(ZimbraSoapContext zsc, CalendarResource cr)
/*     */     throws ServiceException
/*     */   {
/*     */     try
/*     */     {
/* 154 */       checkCalendarResourceRight(zsc, cr, Rights.Admin.R_setCalendarResourcePassword);
/* 155 */       return false;
/*     */     } catch (ServiceException e) {
/* 157 */       if ("service.PERM_DENIED".equals(e.getCode())) {
/* 158 */         checkCalendarResourceRight(zsc, cr, Rights.Admin.R_changeCalendarResourcePassword);
/* 159 */         return true;
/*     */       }
/* 161 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 168 */     relatedRights.add(Rights.Admin.R_setAccountPassword);
/* 169 */     relatedRights.add(Rights.Admin.R_changeAccountPassword);
/* 170 */     relatedRights.add(Rights.Admin.R_setCalendarResourcePassword);
/* 171 */     relatedRights.add(Rights.Admin.R_changeCalendarResourcePassword);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/SetPassword.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */